﻿Imports DTO

Public Class DATimetable

    Inherits DataProvider

    Shared Sub ConfigServerName(ByVal serverName As String)

        ' call constructor base class
        ConfigServer(serverName)

    End Sub

    Shared Function GetTimetable() As DataTable

        Return Query("GetTimetable")

    End Function

    Shared Function GetTimetable0() As DataTable

        Return Query("GetTimtable0")

    End Function

    Shared Function GetRestTime(ByVal dtoTimetable As DTOTimetable) As DataTable

        Dim params As String() = New String() {"@no", "@exFrom", "@exTo"}

        Dim values As Object() = New Object() {dtoTimetable.TimetableNoProperty, dtoTimetable.ExFromProperty, dtoTimetable.ExToProperty}

        Return Query("GetRestTimeByTimetableNo", params, values)

    End Function

    Shared Function AddTimetable(ByVal dtoTimetable As DTOTimetable) As Integer

        ' param name
        Dim params As String() = New String() {"@no", "@name", "@exFrom", "@exTo", "@abbr", "@workFrom", "@workTo",
                                              "@delim", "@unit", "@otUnit", "@status", "@createDate", "@updateDate"}

        'Dim exFrom As Object = dtoTimetable.ExFromProperty

        'If exFrom.ToString().Equals("NULL") Then

        '    exFrom = DBNull.Value

        'End If

        'Dim exTo As Object = dtoTimetable.ExToProperty

        'If exTo.ToString().Equals("NULL") Then

        '    exTo = DBNull.Value

        'End If

        Dim abbre As Object = dtoTimetable.AbreviationProperty

        If abbre.ToString().Equals("NULL") Then

            abbre = DBNull.Value

        End If


        Dim values As Object() = New Object() {dtoTimetable.TimetableNoProperty, dtoTimetable.TimetableNameProperty, dtoTimetable.ExFromProperty,
                                             dtoTimetable.ExToProperty, abbre, dtoTimetable.WorkFromProperty,
                                             dtoTimetable.WorkToProperty, dtoTimetable.DelimitationProperty, dtoTimetable.UnitProperty,
                                             dtoTimetable.OtUnitProperty, "0", Date.Now, Date.Now}

        Return Update("AddTimetable", params, values)

    End Function

    Shared Function AddRestTime(ByVal timetableNo As String, ByVal exFrom As String, ByVal exTo As String,
                                ByVal restFrom As String, ByVal restTo As String) As Integer

        Dim params As String() = New String() {"@timetableNo", "@exFrom", "@exTo", "@restFrom", "@restTo", "@createDate", "@updateDate"}

        Dim values As Object() = New Object() {timetableNo, exFrom, exTo, restFrom, restTo, Date.Now, Date.Now}

        Return Update("AddRestTime", params, values)

    End Function


    ''' <summary>
    '''  delete timetable = set status timetable = 1 and change expiration date to
    ''' </summary>
    ''' <param name="dtoTimetable"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function DeleteTimetable(ByVal dtoTimetable As DTOTimetable, ByVal newExTo As String) As Integer

        Dim params As String() = New String() {"@no", "@exFrom", "@exTo", "@nExTo"}

        Dim values As Object() = New Object() {dtoTimetable.TimetableNoProperty, dtoTimetable.ExFromProperty, dtoTimetable.ExToProperty, newExTo}

        Return Update("DeleteTimetable", params, values)

    End Function

    Shared Function DeleteTimetableExpired(ByVal dtoTimetable As DTOTimetable) As Integer

        Dim params As String() = New String() {"@no", "@exFrom", "@exTo"}

        Dim values As Object() = New Object() {dtoTimetable.TimetableNoProperty, dtoTimetable.ExFromProperty, dtoTimetable.ExToProperty}

        Return Update("DeleteTimetableExpired", params, values)

    End Function

    Shared Function CheckTimetableUsing(ByVal dtoTimetable As DTOTimetable) As Integer

        Dim params As String() = New String() {"@no", "@exFrom", "@exTo", "@now"}

        Dim values As Object() = New Object() {dtoTimetable.TimetableNoProperty, dtoTimetable.ExFromProperty, dtoTimetable.ExToProperty, Date.Now.ToString("yyyyMMdd")}

        Return NonQueryReturn("CheckTimetableUsing", params, values)

    End Function

    ''' <summary>
    ''' actually delete timetable 
    ''' </summary>
    ''' <param name="dtoTimetable"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function DeleteTimetableFuture(ByVal dtoTimetable As DTOTimetable) As Integer

        Dim params As String() = New String() {"@no", "@exFrom", "@exTo"}

        Dim values As Object() = New Object() {dtoTimetable.TimetableNoProperty, dtoTimetable.ExFromProperty, dtoTimetable.ExToProperty}

        Return Update("DeleteTimetableFuture", params, values)

    End Function

    ''' <summary>
    ''' get ex from and ex to timetable by no status = 0
    ''' </summary>
    ''' <param name="no"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetExpTimetable(ByVal no As String) As DataTable

        Return Query("GetExpTimetable", New String() {"@no"}, New Object() {no})

    End Function

    ''' <summary>
    ''' get time table is effecting NO is TIMETABLE_NO + EX FROM + EX_TO
    ''' </summary>
    ''' <param name="startDate"></param>
    ''' <param name="endDate"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetTimetableEffect(ByVal startDate As String, ByVal endDate As String) As DataTable

        Return Query("GetTimetableEffect", New String() {"@startDate", "@endDate"}, New Object() {startDate, endDate})

    End Function


    Shared Function GetTimetable(ByVal timetableNo As String, ByVal exFrom As String, ByVal exTo As String) As DataTable

        Return Query("GetTimetableInfor", New String() {"@timetableNo", "@exFrom", "@exTo"}, New Object() {timetableNo, exFrom, exTo})

    End Function

End Class
